package net.huashitong.synthetical.newSupervision.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.synthetical.newSupervision.entity.TaskWorkable;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2019/7/2
 * Time: 21:02
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Repository
public class TaskWorkableDao extends StringDao<TaskWorkable> {
    public List<TaskWorkable> queryByUserId(String userId) {
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(userId))
            query.append(" and operatorId=:operatorId").setParam("operatorId", userId);
        return query.listResult();
    }

    /**
     * 根据taskId批量删除
     * @param taskIds
     */
    public void deleteByTaskIds(List<String> taskIds) {
        StringBuffer hql = (new StringBuffer("delete from TaskWorkable")).append(" obj where obj.taskId in(:taskIds)");
        Query query = this.getSession().createQuery(hql.toString());
        query.setParameterList("taskIds", taskIds);
        query.executeUpdate();
    }

    /**
     * 根据taskId查询任务执行列表
     * @param taskId
     * @return
     */
    public List<TaskWorkable> queryByTaskId(String taskId) {
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(taskId)){
            query.append(" and taskId=:taskId").setParam("taskId",taskId );
        }
        return query.listResult();
    }
}
